package listbyorder.access201_300.test204;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/22 20:51
 */
public class Solution2 {

    // 精辟的解法————利用数组的特性
    public int countPrimes(int n) {
        if (n <= 2) return 0;
        boolean[] res = new boolean[n];
        int ans = 0;
        for (int i = 2; i < n; i++) {
            if (!res[i]) {
                ans++;
                for (int j = 2; j * i < n; j++) {
                    res[i * j] = true;
                }
            }
        }
        return ans;
    }
}
